<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/commons/global.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>评论管理</title>
</head>

<body>
<script type="text/javascript" src="/static/ext/datagrid-detailview.js"></script>
<script type="text/javascript">

    var commentDataGrid;
    $(function () {
        commentDataGrid = $('#commentDataGrid').datagrid({
            url : '${path }/comment/commentDataGrid.do',
            striped: true,
            rownumbers: true,
            pagination: true,
            singleSelect: true,
            idField: 'id',
            sortName: 'id',
            sortOrder: 'asc',
            pageSize: 20,
            pageList: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
            frozenColumns: [[{
                width: '40',
                title: 'id',
                field: 'id',
                sortable: true
            }]],
            columns : [ [ {
                width : '130',
                title : '用户名',
                field : 'username',
                align:'center'
            }, {
                width : '100',
                title : '手机号',
                field : 'phone',
                align:'center'
            }, {
                width : '80',
                title : '头像',
                field : 'headurl',
                align:'center',
                formatter: function (value, row) {
                    if (value != null) {
                        return '<img height="40px" src="' + value + '" alt="" />';
                    } else {
                        return '';
                    }
                }
            }, {
                width : '200',
                title : '订单号',
                field : 'order_seller_no',
                align:'center'
            },{
                width : '85',
                title : '评价时间',
                field : 'create_time',
                align:'center',
                formatter:function (value, row, index) {
                    return formatDateboxYMD(value,"yyyy-MM-dd hh:mm:ss")
                }
            }, {
                width : '180',
                title : '商家',
                field : 'seller_name',
                align:'center'
            }, {
                width : '210',
                title : '产品',
                field : 'product_name',
                align:'center'
            }, {
                width : '60',
                title : '星级',
                field : 'star',
                align:'center'
            }, {
                width : '60',
                title : '服务',
                field : 'organization_seivice_score',
                align:'center'
            }, {
                width : '60',
                title : '环境',
                field : 'organization_environment_score',
                align:'center'
            }, {
                width : '60',
                title : '速度',
                field : 'organization_speed_score',
                align:'center'
            }, {
                width : '60',
                title : '推荐',
                field : 'is_recommend',
                align:'center',
                formatter:function(value, row){
                    if(value == 0 ){
                        return "否";
                    }else{
                        return "是";
                    }
                }
            }, {
                width : '60',
                title : '状态',
                field : 'status',
                align:'center',
                formatter:function(value, row){
                    if(value == 0 ){
                        return "禁用";
                    }else{
                        return "启用";
                    }
                }
            }, {
                width : '60',
                title : '虚假',
                field : 'is_dummy',
                align:'center',
                formatter:function(value, row){
                    if(value == 0 ){
                        return "否";
                    }else{
                        return "是";
                    }
                }

            },  {
                width : '85',
                title : '回复时间',
                field : 'reply_time',
                align:'center',
                formatter:function (value, row, index) {
                    return formatDateboxYMD(value,"yyyy-MM-dd hh:mm:ss")
                }
            }]],
            view: detailview,
            detailFormatter: function(rowIndex, rowData){
                console.log("rowData.id"+rowData.id);
                return '<div id="imgs_'+rowData.id+'" style="border-top:1px solid #EEEEEE; border-left:1px  solid #EEEEEE;padding:10px;"></div>' +
                    '<div style="padding: 8px 0;border-top:1px solid #EEEEEE;border-left:1px  solid #EEEEEE;">评论内容:</div>' +
                    '<div id="content'+rowData.id+'" style="border-left:1px  solid #EEEEEE;padding: 20px;"></div>'+
                    '<div style="border-top:1px  solid #EEEEEE;border-left:1px  solid #EEEEEE; padding: 8px 0;">回复内容:</div>'+
                    '<div style="border-left:1px  solid #EEEEEE;padding: 20px;" id="reply_content'+rowData.id+'"></div>';
            },


            toolbar : '#commentToolbar',
            onExpandRow : function(index, row) {
                console.log(row.id);
                $.post("${path }/comment/getImages.do",{id:row.id},function (data) {
//                    console.log(data)
                    if(data != null && data.length > 0) {
                        var str = '';
                        for (var i = 0; i < data.length; i++) {
                            str += '<img  height="200px" src="' + data[i].img + '">&nbsp; &nbsp;';
                        }
                        $("#imgs_"+row.id).html(str);
                    }

                });
                $.post("${path }/comment/getCommentContent.do",{id:row.id},function (data) {
                    console.log(data)
                    if(data != null && data.length > 0) {
                        var strc = '';
                        var strr = '';
                        for (var i = 0; i < data.length; i++) {
                            strc += data[i].content;
                            console.log("strc:"+strc)
                            strr += data[i].reply_content;
                            console.log("strr:"+strr)
                        }
                        $("#content"+row.id).html(strc);
                        $("#reply_content"+row.id).html(strr);
                    }

                });
            }
        });
    });

    function addCommentFun() {

        $.modalDialog({
            title : '添加',
            width : 800,
            height : 700,
            href : '${path }/comment/commentAddPage.do',
            id:'commentAddFormPage',
            buttons : [ {
                text : '保存',
                handler : function() {
                    $.modalDialog.openner_treeGrid = commentDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = $.modalDialog.handler.find('#commentAddForm');
                    f.submit();
                }
            } ]
        });
    }

    function editCommentFun() {
        var select = $("#commentDataGrid").datagrid("getSelected");
        if (select == null) {
            $.messager.alert("提示", "请选择要编辑的评论！", "info");
            return;
        }

        $.modalDialog({
            title : '编辑',
            width : 800,
            height : 700,
            href : '${path }/comment/commentEditPage.do?id='+select.id,
            id:'commentEditFormPage',
            buttons : [ {
                text : '保存',
                handler : function() {
                    $.modalDialog.openner_treeGrid = commentDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = $.modalDialog.handler.find('#commentEditForm');
                    f.submit();
                }
            } ]
        });
    }
    function reloadCommentDataGrid() {
        console.log("reload");
        $('#commentDataGrid').datagrid('reload');
    }
    function deleteCommentFun() {
        var select = $("#commentDataGrid").datagrid("getSelected");
        if (select == null) {
            $.messager.alert("提示", "请选择要删除评论！", "info");
            return;
        }

        $.messager.confirm('询问', '您确定要删除此评论吗?', function (b) {
            if (b) {
                progressLoad();
                $.post('${path }/comment/delete.do', {'id': select.id}, function (result) {
                    if (result.success) {
                        $.messager.alert('提示', result.msg, 'info');
                        reloadCommentDataGrid();
                        $('#commentDataGrid').datagrid('clearSelections');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }
</script>
<div class="easyui-layout" fit="true">
    <div data-options="region:'center',border:true,title:'评论管理'" >
        <table id="commentDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="commentToolbar" style="display: none;">
    <shiro:hasPermission name="/user/add.do">
        <a onclick="addCommentFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="/user/add.do">
        <a onclick="editCommentFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-pencil icon-green'">编辑</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="/user/add.do">
        <a onclick="deleteCommentFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-x icon-green'">删除</a>
    </shiro:hasPermission>
</div>
</body>

</html>
